/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wowmobile;

import java.util.List;
import java.util.Random;

/**
 *
 * @author Ksysu
 */
public class Quest
{
    String name; //unique
    String description;
    int type;
    int howMany;
    int done;
    Monster monster;
    String item;
    
    public Quest()
    {
        name="You dont have a quest";
    }
    
    public Quest(String name, String description, int howMany, Monster monster)
    {
        this.name=name;
        this.description=description;
        this.type=0;
        this.howMany=howMany;
        this.monster=monster;
        done=0;
    }
    
    public Quest(String name, String description, int howMany, Monster monster, String item)
    {
        this.name=name;
        this.description=description;
        this.type=1;
        this.howMany=howMany;
        this.monster=monster;
        this.item=item;
        done=0;
    }
    
    public boolean isFinished()
    {
        if(howMany<=done)
            return true;
        else
            return false;
    }

    public boolean isQuest()
    {
        if(name.equals("You dont have a quest"))
            return false;
        else
            return true;
    }
    
    public String updateDone(List<Monster> list)
    {
        int count=0;
        for(int i=0; i<list.size(); i++)
            if(list.get(i).getName().equals(monster.getName()))
                count++;
        if(type==0)
        {
            done+=count;
            if(isFinished())
            {
                return "Zadanie "+name+" zostalo ukonczone";

            }
            else
                return "Zabiles "+count+" "+monster.getName();
        }
        else if(type==1)
        {
            Random r=new Random();
            int items=0;
            while(count>0)
            {
                if(r.nextInt()>50)
                    items++;
                count--;
            }
            done+=items;
            if(isFinished())
                return "Zadanie "+name+" zostalo ukonczone";
            else
                return "Zdobyles "+count+" "+item;
        }
        return "";
    }

    public String toString()
    {
        if(!isQuest())
            return name;
        else
            return name+"\n"+description+"\n"+done +"/"+howMany;
    }
}